import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' // svg插件
import { viteMockServe } from 'vite-plugin-mock' // mock插件

export default defineConfig(({ command }) => {
  return {
    plugins: [vue(), createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
      symbolId: 'icon-[dir]-[name]',
    }),
    viteMockServe({
      localEnabled: command === 'serve', //保证开发阶段可以使用mock接口
    }),
    ],
    resolve: {
      alias: {
        "@": path.resolve("./src") // 相对路径别名配置，使用 @ 代替 src
      }
    },
    // scss全局变量配置
    css: {
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: '@import "./src/styles/variable.scss";',
        },
      },
    },
    // 代理跨域
    server: {
      host:'0.0.0.0',
      port:5174,
      proxy: {
        '/api': {
          // target: 'http://192.168.30.142:8081', //开发
          // target: 'http://192.168.0.171:9005', //线上
          target: 'http://localhost:9006',  //打包
          changeOrigin: true, //是否代理跨域
          rewrite: (path) => path
        }
      }
    },
  }
})
